package com.yc.damai.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.yc.damai.dao.ProductDao;

@WebServlet("/type.s")
public class TypeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	private ProductDao pdao = new ProductDao();   
   
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		String cid = request.getParameter("cid");
		
		// 获取分页参数
		String page = request.getParameter("page");
		page = page == null ? "1" : page;
		int pageIndex = Integer.parseInt(page);
		
		// 分页查询
		//List<VO> list = pdao.queryByType(cid, pageIndex);
		
		Gson g = new Gson();
		String json = g.toJson(pdao.queryByType(cid, pageIndex));
		
		response.getWriter().append(json);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
